

* Monte Carlo simulations
* ---------------------------------------------	*
* 			Do preparations						*
* ---------------------------------------------	*

di "Starting `pvers' `rname'"

* Create data container:
* -----------------------

* Creating a empty storage .dta file to record all of our simulations
clear
set obs 1
gen run=. 
save ${monte_data_dir}/storage_runs_`pvers'_`rname'.dta, replace

* Prepare permutation specific input:
* -----------------------------------

di "Preparing input datasets for `pvers' `rname'"
qui include ${monte_dir}/input_permute_`pvers'.do

* ---------------------------------------------	*
* 			Run Monte Carlo Simulation			*
* ---------------------------------------------	*


forvalue run = 1 / `monte_runs' {
	di "=========== Run # `run' / `monte_runs' =============="

	* Redraw countries of firm weights
	* --------------------------------
    di "run `run' `rname' - redrawing `pvers', rebuild dataset"
	qui include ${monte_dir}/redraw_permute_`pvers'.do
	
	* Run regressions:
	* ----------------
	include ${monte_dir}/run_regressions.do

	* Save redrawn values for BH
	* --------------------------
	if (`run_boruhull' == 1) include ${monte_dir}/save_mu_terms.do

	* Store run results:
	* -----------------
    di "run `run' - storing results (`pvers' `rname')"
	qui include ${monte_dir}/save_run.do
}


